program define rwanda_regressions, nclass
			
	syntax varlist, [savename(string) title(string) addnote(string)]

	di "`addnote'"

qui eststo sumtable: estpost tabstat `varlist',  /*
		*/ by(rollout) stat(mean sd count) c(stat) 

	esttab sumtable using "$d_out/`savename'_summtable.tex", $tab_note1 $tab_note2 /*
		*/  title("\label{tab:`savename'}Summary statistics: `title'") /*
		*/ 	note("Standard deviations in parentheses.  Sample sizes in brackets")
	

*** DROPPING HOSPITALS
preserve

	drop if factype==1
	drop if treatment==2
	
	local clinic_control="has_genout has_anc has_tb has_hiv has_inmed"
	local other_control="funds_equity funds_emp funds_ins funds_pool"

	
	foreach var in `varlist' {
		eststo no_control_`var', add(num_obs e(N)): qui xi: reg `var' i.treatment	
		eststo fac_control_`var', add(num_obs e(N)): qui xi: reg `var' i.treatment i.factype adjac private logcatch i.province 
		eststo fac_con2_`var', add(num_obs e(N)): qui xi: reg `var' i.treatment i.factype adjac private logcatch i.province `clinic_control' `other_control'
		eststo fac_conint_`var', add(num_obs e(N)): qui xi: reg `var' i.treatment*private i.factype adjac logcatch i.province `clinic_control' `other_control'
		
		
		lab var _Itreatment_1 "Treatment"
		lab var _Ifactype_3 "Health post"
		lab var _ItreXpriva_1 "Treatment X Private"
		lab var _Iprovince_2 "Southern province"
		lab var _Iprovince_3 "Eastern province"
		lab var _Iprovince_4 "Western province"
		lab var _Iprovince_5 "Kigali City" 
		
		
		esttab no_control_`var' fac_control_`var' fac_con2_`var' fac_conint_`var' /*
			*/ using "$d_out/`var'_reg.tex", $regtab_opts /*
			*/  title("\label{tab:`var'} Regression results: $`var'_desc")  

		drop _I*
		

	}
restore

* COMPILING REGRESSION RESULTS
local compile_reg_foot2 "footnote("P-values are for two sided tests. Regressions controls include: log catchment population, log per capita spending, public/private facility, whether or not facility is a health post, types of clinics available in facility, and available funding types. `addnote'")"

preserve
	compile_results `varlist', est(fac_con2)
	
	texsave_dngo outcome cmean b se p num_obs using "$d_out/`savename'_results.tex", replace /*
		*/ align(lccccc) varlabels rowsep(0.5cm) /*
		*/ title(Treatment effects: `title') marker(`savename') /*
		*/ headlines("") frag nofix /*
		*/ `compile_reg_foot2'
		
	save "$d_interm/`savename'_results", replace
	
	
	
restore

eststo clear

end
